# -*- coding: utf-8 -*-
"""
Created on Thu Jan  2 13:18:56 2020

@author: Administrator
"""

import os
import sys
import csv

def rename():
    doc_path = "1. word下载"
    csv_path = "PDF下载.csv"
    list_file = os.listdir(doc_path)
    title_list = []
    list_url = []
    with open(csv_path, 'r', encoding="utf-8-sig", newline='') as f:
        next(f)
        reader = csv.reader(f)
        for line in reader:
            title_list.append(line[2])
            list_url.append(line[-1])
    target_list = list(zip(title_list,list_url))

    for file in list_file:
        doc_name = file.split(".")[0]
        doc_type = file.split(".")[1]
        for t in target_list:
            if t[1].find(doc_name) > 0:
                os.rename(doc_path + "/" + file, doc_path + "/" + t[0] + "." + doc_type)


if __name__ == "__main__":
    rename()

